﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using System.Text;

namespace WebSite.cn
{
    public partial class index : BasePage
    {
        public StringBuilder sbFieldsNews = new StringBuilder();
        public StringBuilder sbCrabCulture = new StringBuilder();
        public StringBuilder sbCrabKnowledge = new StringBuilder();

        string sCardFormat = " <TABLE style=\"margin-top: 5px;margin-left: 5px; float: left; border:5px solid #DEDEDE;\"  cellSpacing=\"0\" cellPadding=\"5\" width=\"200\" align=\"center\" height=\"200\">"
                            + " <TBODY> "
                            +" <TR> "
                            +" <TD  height=\"200\" align=\"center\"><A title=\"{0}\""
                            +" href=\"{1}\" target=\"_self\">"
                            +" <IMG border=\"0\" src=\"{2}\" width=\"200\" height=\"200\"></A> </TD></TR>"
                            + " <tr bgColor=\"#e2e2e2\"> <td style='padding-top:10px;' class=\"scrollTitle\"> {0}</td></tr>"
                            +" </TBODY></TABLE>";
        public StringBuilder sbCardList = new StringBuilder();

        public string IsHave
        {
            get
            {
                if (new BasePage().IsHavePop == null) return null;
                else return new BasePage().IsHavePop;
            }
            set { new BasePage().IsHavePop = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindNews();
                this.BindProductList();
            }
            if (!IsPostBack)
            {
                if (IsHave == null)
                {
                    IsHave = "true";
                }
            }
            else
            {
                IsHave = "false";
            }
        }



        public void BindNews()
        {
            string sSQL = "select newsid, newsname,updatetime,typeid from DB_News where 1=1 and typeid in(1,2,3) order by newsorder asc, updatetime desc ";

            DataTable table = SQLAccess.GreatDs(sSQL).Tables[0];

            if (table.Rows.Count > 0)
            {
                string sFormat = " <TR> "
                                        + " <TD class=\"list\"><A title=\"{4}\" "
                                        + " href=\"news_01.aspx?tid={0}&nid={1}\" target='_blank'>{2} "
                                        + " </A></TD><td class=\"list\" width='72px'>[{3}]</td></TR>";
                int iFieldsCount = 0;
                int iCrabKnowledge = 0;
                int iCrabCulture = 0;
                int maxCount = 8;
                foreach (DataRow dr in table.Rows)
                {
                    if (dr["typeid"].ToString() == "1")
                    {
                        if (iFieldsCount > maxCount) continue;
                        this.sbFieldsNews.AppendFormat( sFormat
                            , dr["typeid"].ToString()
                            , dr["newsid"].ToString()
                            , dr["newsname"].ToString().Length > 10 ? dr["newsname"].ToString().Substring(0,10) + ".." : dr["newsname"].ToString()
                            , DateTime.Parse(dr["updatetime"].ToString()).ToString("yyyy-MM-dd")
                            ,  dr["newsname"].ToString()
                            );
                    }
                    else if (dr["typeid"].ToString() == "2")
                    {

                        if (iCrabKnowledge > maxCount) continue;
                        this.sbCrabKnowledge.AppendFormat(sFormat
                            , dr["typeid"].ToString()
                            , dr["newsid"].ToString()
                           , dr["newsname"].ToString().Length > 10 ? dr["newsname"].ToString().Substring(0,10) + ".." : dr["newsname"].ToString()
                            , DateTime.Parse(dr["updatetime"].ToString()).ToString("yyyy-MM-dd")
                            , dr["newsname"].ToString()
                              );
                    }
                    else if (dr["typeid"].ToString() == "3")
                    {
                        if (iCrabCulture > maxCount) continue;
                        this.sbCrabCulture.AppendFormat(sFormat
                            , dr["typeid"].ToString()
                            , dr["newsid"].ToString()
                            , dr["newsname"].ToString().Length > 10 ? dr["newsname"].ToString().Substring(0,10) + ".." : dr["newsname"].ToString()
                            , DateTime.Parse(dr["updatetime"].ToString()).ToString("yyyy-MM-dd")
                            , dr["newsname"].ToString()
                              );
                    }
                }
            }
        }

        void BindProductList()
        {
            DataTable table;
            string sql = "select shuxiname,pic from DB_Shuxintype where shuxinid=5";
            table = SQLAccess.GreatDs(sql).Tables[0];
            int numTop = 0;
            if (table.Rows.Count > 0)
            {
                numTop = Convert.ToInt32(info.info1("", "homeshowpnum3"));
            }
            table = SQLAccess.GreatDs("select top " + numTop.ToString() + "  proid,proname,propic1,proprice1,proprice3,propic2,typeid,instruction from DB_Shoppro where visible=1 and proisshow=1 and proisnew3=1 and isnull(proku1,0)>0 order by proorder").Tables[0];
            if (table.Rows.Count > 0)
            {
               
                foreach (DataRow row4 in table.Rows)
                {
                    sbCardList.AppendFormat(sCardFormat
                                            , row4["proname"].ToString()
                                            , "products_details.aspx?pid=" + row4["proid"].ToString() + "&sid=3"
                                            , "/uploadfile/product/" + row4["propic1"].ToString()
                                            );

                }
            }
        }

  
    }
}